Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce support for 'gpt-4-1106-preview' model and dynamic token limit calculation #437

Merged
merged 3 commits into from
Nov 7, 2023

Conversation

mrT23
Copy link
Collaborator

@mrT23 mrT23 commented Nov 7, 2023

PR Type:

Enhancement


PR Description:

  • Added support for the 'gpt-4-1106-preview' model with a token limit of 128,000.
  • Implemented a new function get_max_tokens to dynamically calculate the maximum number of tokens based on model capabilities and configuration limits.
  • Updated various parts of the code to use the new get_max_tokens function instead of the static MAX_TOKENS dictionary.
  • Adjusted the configuration.toml to include a new max_model_tokens setting to allow limiting the number of tokens used, regardless of the model's maximum.

PR Main Files Walkthrough:

files:
  • pr_agent/algo/__init__.py: Added 'gpt-4-1106-preview' model with a token limit of 128,000 to the MAX_TOKENS dictionary.
  • pr_agent/algo/utils.py: Introduced the get_max_tokens function that returns the maximum number of tokens for a given model, considering the max_model_tokens setting from the configuration.
  • pr_agent/algo/pr_processing.py: Replaced static MAX_TOKENS dictionary usage with the get_max_tokens function to dynamically calculate token limits during PR processing.
  • pr_agent/tools/pr_similar_issue.py: Updated to use get_max_tokens instead of MAX_TOKENS for token count checks when processing issues.
  • pr_agent/settings/configuration.toml: Added a new max_model_tokens setting to allow configuration of a maximum token limit for models.

@mrT23
Copy link
Collaborator Author

mrT23 commented Nov 7, 2023

/describe

@github-actions github-actions bot changed the title get_max_tokens + added 'gpt-4-1106-preview' Add support for 'gpt-4-1106-preview' model and implement get_max_tokens function Nov 7, 2023
@github-actions github-actions bot added the enhancement New feature or request label Nov 7, 2023
Copy link
Contributor

github-actions bot commented Nov 7, 2023

PR Analysis

  • 🎯 Main theme: This PR introduces a new model 'gpt-4-1106-preview' and refactors the way maximum tokens are handled across different models.
  • 📝 PR summary: The PR adds a new model 'gpt-4-1106-preview' to the list of models and its corresponding max tokens. It also refactors the code to handle the maximum tokens allowed by a model. Instead of using a constant, a function 'get_max_tokens' is introduced which takes into account the model's max tokens and a configurable max tokens limit.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 2, because the PR is not very large and the changes are straightforward. However, the impact of the changes is significant and requires careful review.
  • 🔒 Security concerns: No security concerns found

PR Feedback

  • 💡 General suggestions: The PR is well-structured and the changes are logically grouped. However, it would be beneficial to add tests to verify the new functionality. Also, it would be good to add logging in the 'get_max_tokens' function to track when the max tokens are limited by the config value.

  • 🤖 Code feedback:

    • relevant file: pr_agent/algo/utils.py
      suggestion: Consider adding logging in the 'get_max_tokens' function to track when the max tokens are limited by the config value. This can be helpful for debugging and understanding the system's behavior. [medium]
      relevant line: '+ return max_tokens_model'

    • relevant file: pr_agent/algo/pr_processing.py
      suggestion: It would be beneficial to handle the case when the model is not found in the MAX_TOKENS dictionary in the 'get_max_tokens' function. This can prevent potential errors and make the code more robust. [important]
      relevant line: '+ if total_tokens + OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD < get_max_tokens(model):'

How to use

To invoke the PR-Agent, add a comment using one of the following commands:
/review [-i]: Request a review of your Pull Request. For an incremental review, which only considers changes since the last review, include the '-i' option.
/describe: Modify the PR title and description based on the contents of the PR.
/improve [--extended]: Suggest improvements to the code in the PR. Extended mode employs several calls, and provides a more thorough feedback.
/ask <QUESTION>: Pose a question about the PR.
/update_changelog: Update the changelog based on the PR's contents.

To edit any configuration parameter from configuration.toml, add --config_path=new_value
For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
To list the possible configuration parameters, use the /config command.

@mrT23 mrT23 requested a review from hussam789 November 7, 2023 12:31
@mrT23 mrT23 changed the title Add support for 'gpt-4-1106-preview' model and implement get_max_tokens function Introduce support for 'gpt-4-1106-preview' model and dynamic token limit calculation Nov 7, 2023
@mrT23
Copy link
Collaborator Author

mrT23 commented Nov 7, 2023

PR Analysis

  • 🎯 Main theme: Introduction of support for a new GPT-4 model and dynamic token limit calculation.
  • 📝 PR summary: This PR adds support for the 'gpt-4-1106-preview' model with a token limit of 128,000 and implements a function to dynamically calculate token limits. It updates the codebase to use this new function and adds a configuration option to set a maximum token limit.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 3, because the PR involves understanding the token calculation logic and ensuring that the new dynamic token limit calculation is correctly integrated across multiple files.
  • 🔒 Security concerns: No security concerns found

PR Feedback

  • 💡 General suggestions: The PR introduces a significant enhancement by adding support for a new model and improving the flexibility of token limit calculations. It is important to ensure that the new get_max_tokens function is robust and that all parts of the code that previously relied on static token limits are updated accordingly. Additionally, it would be beneficial to include tests to verify the behavior of the new function, especially since token limits can be a critical part of the system's functionality.

  • 🤖 Code feedback:

pr_agent/algo/__init__.py Show resolved Hide resolved
Comment on lines 347 to 353
def get_max_tokens(model):
max_tokens_model = MAX_TOKENS[model]
if get_settings().config.max_model_tokens:
if max_tokens_model > get_settings().config.max_model_tokens:
max_tokens_model = get_settings().config.max_model_tokens
# get_logger().debug(f"limiting max tokens to {max_tokens_model}")
return max_tokens_model
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Refactor the 'get_max_tokens' function to use a local variable for settings to avoid multiple calls to 'get_settings()' which may be inefficient if it involves I/O operations or complex computations.

Suggested change
def get_max_tokens(model):
max_tokens_model = MAX_TOKENS[model]
if get_settings().config.max_model_tokens:
if max_tokens_model > get_settings().config.max_model_tokens:
max_tokens_model = get_settings().config.max_model_tokens
# get_logger().debug(f"limiting max tokens to {max_tokens_model}")
return max_tokens_model
def get_max_tokens(model):
settings = get_settings()
max_tokens_model = MAX_TOKENS[model]
if settings.config.max_model_tokens and max_tokens_model > settings.config.max_model_tokens:
max_tokens_model = settings.config.max_model_tokens
# get_logger().debug(f"limiting max tokens to {max_tokens_model}")
return max_tokens_model

Comment on lines 347 to 353
def get_max_tokens(model):
max_tokens_model = MAX_TOKENS[model]
if get_settings().config.max_model_tokens:
if max_tokens_model > get_settings().config.max_model_tokens:
max_tokens_model = get_settings().config.max_model_tokens
# get_logger().debug(f"limiting max tokens to {max_tokens_model}")
return max_tokens_model
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add a guard clause to 'get_max_tokens' to handle the case where the model is not found in the MAX_TOKENS dictionary, which would currently raise a KeyError.

Suggested change
def get_max_tokens(model):
max_tokens_model = MAX_TOKENS[model]
if get_settings().config.max_model_tokens:
if max_tokens_model > get_settings().config.max_model_tokens:
max_tokens_model = get_settings().config.max_model_tokens
# get_logger().debug(f"limiting max tokens to {max_tokens_model}")
return max_tokens_model
def get_max_tokens(model):
if model not in MAX_TOKENS:
raise ValueError(f"Model '{model}' not found in MAX_TOKENS dictionary.")
max_tokens_model = MAX_TOKENS[model]
settings = get_settings()
if settings.config.max_model_tokens and max_tokens_model > settings.config.max_model_tokens:
max_tokens_model = settings.config.max_model_tokens
# get_logger().debug(f"limiting max tokens to {max_tokens_model}")
return max_tokens_model

@@ -10,6 +10,7 @@ use_repo_settings_file=true
ai_timeout=180
max_description_tokens = 500
max_commits_tokens = 500
max_model_tokens = 32000 # even if a model supports more tokens, quality may degrade. Hence, enable to limit the number of tokens.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The 'max_model_tokens' setting should be documented to explain its purpose and effect on the system, especially since it overrides the model's default token limit.

Suggested change
max_model_tokens = 32000 # even if a model supports more tokens, quality may degrade. Hence, enable to limit the number of tokens.
# Limits the maximum number of tokens that can be used by any model, regardless of the model's default capabilities.
# This can be useful to ensure consistent performance and to prevent issues related to large token counts.
max_model_tokens = 32000

Comment on lines 350 to 351
if max_tokens_model > get_settings().config.max_model_tokens:
max_tokens_model = get_settings().config.max_model_tokens
Copy link
Collaborator

@hussam789 hussam789 Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, Use the min function:

max_tokens_model = min(max_tokens_model, get_settings().config.max_model_tokens)

@mrT23
Copy link
Collaborator Author

mrT23 commented Nov 7, 2023

Incremental PR Review

  • ⏮️ Review for commits since previous PR-Agent review: Starting from commit 094f641
    (code)

PR Analysis

  • 🎯 Main theme: Introducing support for a new model and dynamic token limit calculation.
  • 📝 PR summary: This PR adds support for the 'gpt-4-1106-preview' model with a specific token limit and implements a function to dynamically calculate the maximum token limit based on model capabilities and configuration settings. It also updates various parts of the code to use this new function and adds a setting to limit tokens in the configuration file.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 3, because the PR involves understanding the new dynamic token calculation logic and ensuring it integrates correctly with existing systems. It also requires verifying that the new configuration setting is properly used across the codebase.
  • 🔒 Security concerns: No

PR Feedback

  • 💡 General suggestions: The PR seems to be well-structured and targets a specific enhancement. It would be beneficial to ensure that there are tests accompanying this new functionality to verify the dynamic token calculation works as expected across different scenarios and model configurations. Additionally, it's important to check that the new configuration setting is documented clearly for end-users.

  • 🤖 Code feedback:

@mrT23 mrT23 merged commit 6c82bc9 into main Nov 7, 2023
2 checks passed
@mrT23 mrT23 deleted the tr/new_gpt4 branch November 7, 2023 12:49
yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
Introduce support for 'gpt-4-1106-preview' model and dynamic token limit calculation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants